﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dziennik_ProfilNauczyciela {
    public partial class Form_ZmianaHasla : Form {
        public Form_ZmianaHasla() {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e) {
            Close();
        }

        private void button1_Click(object sender, EventArgs e) {
            if (textBox_NoweHaslo1.Text == "" || textBox_NoweHaslo2.Text == "" || textBox_StareHaslo.Text == "") {
                label_Blad.Text = "Wypełnij wszystkie pola!";
            }
            else if (textBox_NoweHaslo1.Text != textBox_NoweHaslo2.Text) {
                label_Blad.Text = "Nowe hasła nie są identyczne!";
            }
            else {
                string login = "dziennik_" + SQLInterface.linqDataContext.getUserName();
                try {
                    SQLInterface.linqDataContext.zmienHaslo(textBox_StareHaslo.Text, textBox_NoweHaslo1.Text);
                }
                catch (Exception ex) {
                    label_Blad.Text = "Niewłaściwe stare hasło!";
                    return;
                }
                Close();
            }
        }
    }
}
